﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScaleChange : MonoBehaviour
{
    private float scaleDuration = 1f; // 缩放持续时间  
    private float scaleProgress = 0f; // 当前缩放进度  
    private bool isScalingDown = true; // 是否正在缩小  

    void Start()
    {
        transform.localScale = Vector3.one; // 初始化按钮缩放为1  
    }

    void FixedUpdate()
    {
        if (isScalingDown)
        {
            // 计算缩放进度  
            scaleProgress += Time.fixedDeltaTime / scaleDuration;
            transform.localScale = Vector3.Lerp(Vector3.one, new Vector3(0.75f, 0.75f, 1.0f), scaleProgress);

            // 检查是否完成缩放到0  
            if (scaleProgress >= 1f)
            {
                scaleProgress = 0f; // 重置进度  
                isScalingDown = false; // 切换到放大状态  
            }
        }
        else
        {
            // 计算缩放进度  
            scaleProgress += Time.fixedDeltaTime / scaleDuration;
            transform.localScale = Vector3.Lerp(new Vector3(0.75f, 0.75f, 1.0f), Vector3.one, scaleProgress);

            // 检查是否完成放大到1  
            if (scaleProgress >= 1f)
            {
                scaleProgress = 0f; // 重置进度  
                isScalingDown = true; // 切换到缩小状态  
            }
        }
    }
}
